﻿using System;
using System.Collections.Generic;
using Myotragus.Data.Domain;
using Myotragus.Data.Metadata;
using Myotragus.Data.Util;

namespace Myotragus.Data.Emit
{
	public class DefaultsLoadEntityGenerator : LocalizableOperationEntityGenerator, IDefaultsLoadEntityGenerator
	{
		protected static readonly Type TypeOfTextList = typeof(IList<LocalizableText>);
		protected static readonly Type TypeOfDefaultTextList = typeof(IList<DefaultsLoadLocalizableText>);

		public DefaultsLoadEntityGenerator(IDynamicAssembly dynamicAssembly, INameGenerator nameGenerator,
			ILocalizableEntityMapping mapping)
			: base(dynamicAssembly, nameGenerator, mapping)
		{
		}

		protected static readonly Type TypeOfIDefaultsLoadEntity = typeof(IDefaultsLoadEntity<>);

		protected override Type BaseInterfaceType
		{
			get { return TypeOfIDefaultsLoadEntity; }
		}

		protected override void AttachLocalizableProperty(IDynamicType type, string name)
		{
			type.DefineAutomaticProperty(name, TypeOfTextList);
			type.DefineAutomaticProperty(EmitHelper.CreateDefaultsName(name), TypeOfDefaultTextList);
		}
	}
}